package daobeauty.test.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;

import daobeauty.dao.SessionFactoryAware;
import daobeauty.test.domain.D1;

/**
 * Created 12.09.2008
 * @author M. Serhat Cinar
 *
 */
public class D1Delegate implements SessionFactoryAware {
	private SessionFactory sessionFactory;
	/* (non-Javadoc)
	 * @see daobeauty.dao.hibernate.SessionFactoryAware#getCurrentSession()
	 */
	public Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
	}

	/* (non-Javadoc)
	 * @see daobeauty.dao.hibernate.SessionFactoryAware#getSessionFactory()
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/* (non-Javadoc)
	 * @see daobeauty.dao.hibernate.SessionFactoryAware#setSessionFactory(org.hibernate.SessionFactory)
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	
	public D1 findByHighestId(){
		return (D1) getCurrentSession().createCriteria(D1.class).addOrder(Order.desc("id")).setMaxResults(1).uniqueResult();
	}
}
